//
//  XYWelComController.swift
//  WeiboSourceCode
//
//  Created by 周星宇 on 15/12/29.
//  Copyright © 2015年 cn.weibo. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class XYWelComController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        if let headImageString = XYUserAccountViewModel.sharedUserAccountViewModel.xUserAount?.avatar_large {
            iconView.sd_setImageWithURL(NSURL(string: headImageString), placeholderImage: UIImage(named: "avatar_default_big"))
            
        }
        
        setUpUI()
    }
    
    // 动画设置
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(true)
        
        // 修改约束
        iconView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view).offset(100)
        }
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            self.view.layoutIfNeeded()
        }) { (_) -> Void in
            
            UIView.animateWithDuration(1, animations: { () -> Void in
                
                self.messageLabel.alpha = 1
                
            }, completion: { (_) -> Void in
                // 跳转控制器
                NSNotificationCenter.defaultCenter().postNotificationName(changeRootViewControllerNotification, object: nil)
            })
        }
        
        
    }
    private func setUpUI() {
        
        
        view.backgroundColor = UIColor(white: 247/255, alpha: 1)
        view.addSubview(iconView)
        view.addSubview(messageLabel)
        
        iconView.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(200)
            make.size.equalTo(CGSizeMake(90, 90))
            
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(view)
            make.top.equalTo(iconView.snp_bottom).offset(10)
            
        }
        
        
    }
    // MARK: 懒加载控件
    private lazy var iconView: UIImageView = {
        
        let iconView = UIImageView()
        iconView.image = UIImage(named: "avatar_default_big")
        iconView.layer.cornerRadius = 45
        iconView.clipsToBounds = true
        return iconView
    }()
    private lazy var messageLabel: UILabel = {
        
        let messageLabel = UILabel()
        messageLabel.textColor = UIColor.darkGrayColor()
        messageLabel.font = UIFont.systemFontOfSize(16)
        messageLabel.text = "欢迎回来"
        messageLabel.alpha = 0
        return messageLabel
    }()
    
}
